<?php

include 'confidential_settings.php';
// This include contains 5 variables:
//  - db_name: database name
//  - table_name_x: table name
//  - username: username
//  - password: password
//  - localhost: host name

$dbh=mysql_connect ($localhost, $username, $password) or die('Cannot connect to the database because: ' . mysql_error());

mysql_select_db ($db_name) or die(mysql_error()); 


$result = mysql_query("SELECT COUNT(val), DATE(date_entered), SUM(val) FROM $table_name_gas WHERE DATE_SUB(CURDATE(),INTERVAL 3 MONTH) <= DATE(date_entered) GROUP BY YEAR(date_entered), MONTH(date_entered), DAY(date_entered)");

echo "<br /><br />DAY VALUES:<br />";
while($row = mysql_fetch_array($result)){
	echo $row['DATE(date_entered)'] . "\t" . $row['SUM(val)'] . "\t   (" . $row['COUNT(val)'] . " entries)";
	echo "<br />";
}

echo "<br />";

$result = mysql_query("SELECT * FROM $table_name_gas_ns");
 
echo "<br /><br />DETAILED VALUES (NO SUCCEED TABLE):<br />";
while($row = mysql_fetch_array($result)){
	echo $row['val'] . " - " . $row['date_entered'];
	echo "<br />";
}

echo "<br />";

$result = mysql_query("SELECT * FROM $table_name_gas WHERE DATE_SUB(CURDATE(),INTERVAL 3 MONTH) <= DATE(date_entered)");
 
echo "<br /><br />DETAILED VALUES:<br />";
while($row = mysql_fetch_array($result)){
	echo $row['val'] . " - " . $row['date_entered'];
	echo "<br />";
}


mysql_close($dbh);

?>
